" 把 .vim 目录放到 /home/<user name> 目录下，配置即可生效

" 语法高亮
syntax on
" 自动缩进
set autoindent  
set cindent  

" tab 键的宽度  
set tabstop=4
" 使用空格代替 tab
set expandtab
" 统一缩进为 4
set softtabstop=4  
set shiftwidth=4
" 解决不能在插入模式使用删除键
set backspace=indent,eol,start
" 高亮光标所在行
set cursorline
" 高亮光标所在列
set cursorcolumn

" 搜索设置
set hlsearch
set incsearch
" 搜索时忽略大小写
"set ignorecase
" 如果搜索含大写字母，则自动变为大小写敏感
set smartcase

" 在 normal 模式，光标停止一些时间后触发 checktime 检查文件变更
au CursorHold * checktime

" 编码
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

" 显示行号
set nu!
" 显示状态栏
set laststatus=2
" 光标上下有多少行保留
set scrolloff=10
" 可以使用鼠标
set mouse=a
" 光标所在行提示
set cursorline

" 颜色方案
set t_Co=256
let g:molokai_original=1
colorscheme molokai
" colorscheme morning


" 标签页显示索引 Rename tabs to show tab number.
" (Based on http://stackoverflow.com/questions/5927952/whats-implementation-of-vims-default-tabline-function)
if exists("+showtabline")
    function! MyTabLine()
        let s = ''
        let wn = ''
        let t = tabpagenr()
        let i = 1
        while i <= tabpagenr('$')
            let buflist = tabpagebuflist(i)
            let winnr = tabpagewinnr(i)
            let s .= '%' . i . 'T'
            let s .= (i == t ? '%1*' : '%2*')
            let s .= ' '
            let wn = tabpagewinnr(i,'$')

            let s .= '%#TabNum#'
            let s .= i
            " let s .= '%*'
            let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')
            let bufnr = buflist[winnr - 1]
            let file = bufname(bufnr)
            let buftype = getbufvar(bufnr, 'buftype')
            if buftype == 'nofile'
                if file =~ '\/.'
                    let file = substitute(file, '.*\/\ze.', '', '')
                endif
            else
                let file = fnamemodify(file, ':p:t')
            endif
            if file == ''
                let file = '[No Name]'
            endif
            let s .= ' ' . file . ' '
            let i = i + 1
        endwhile
        let s .= '%T%#TabLineFill#%='
        let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
        return s
    endfunction
    set stal=2
    set tabline=%!MyTabLine()
    set showtabline=1
    highlight link TabNum Special
endif

" 键盘映射 map
" 设置 leader 和 local leader 按键
let mapleader="-"
let maplocalleader="\\"

" 插件配置 plugin config
" 需要设置 runtimepath 指定插件所在目录
""""""
" ctrlp
set runtimepath^=~/.vim/bundle/ctrlp.vim
let g:ctrlp_custom_ignore = {
    \ 'dir':  '\v[\/]\.(git|hg|svn|rvm)$',
    \ 'file': '\v\.(exe|so|dll|zip|tar|tar.gz|pyc|meta)$',
    \ }
let g:ctrlp_max_height=30

""""""
" ctrlp-funky
set runtimepath^=~/.vim/bundle/ctrlp-funky
let g:ctrlp_funky_matchtype = 'path'
nnoremap <Leader>fu :CtrlPFunky<Cr>
" narrow the list down with a word under cursor
nnoremap <Leader>fU :execute 'CtrlPFunky ' . expand('<cword>')<Cr>

""""""
" neocomplcache
set runtimepath^=~/.vim/bundle/neocomplcache.vim
" Disable AutoComplPop.
let g:acp_enableAtStartup = 0
" Use neocomplcache.
let g:neocomplcache_enable_at_startup = 1
" Use smartcase.
let g:neocomplcache_enable_smart_case = 1
" Set minimum syntax keyword length.
let g:neocomplcache_min_syntax_length = 3
let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'

" Recommended key-mappings.
" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
  return neocomplcache#smart_close_popup() . "\<CR>"
  " For no inserting <CR> key.
  "return pumvisible() ? neocomplcache#close_popup() : "\<CR>"
endfunction
" <TAB>: completion.
inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"
" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><C-h> neocomplcache#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>"
inoremap <expr><C-y>  neocomplcache#close_popup()
inoremap <expr><C-e>  neocomplcache#cancel_popup()

" For cursor moving in insert mode(Not recommended)
"inoremap <expr><Left>  neocomplcache#close_popup() . "\<Left>"
"inoremap <expr><Right> neocomplcache#close_popup() . "\<Right>"
"inoremap <expr><Up>    neocomplcache#close_popup() . "\<Up>"
"inoremap <expr><Down>  neocomplcache#close_popup() . "\<Down>"
" Or set this.
let g:neocomplcache_enable_cursor_hold_i = 1
" Or set this.
"let g:neocomplcache_enable_insert_char_pre = 1

""""""
" easygrep
set runtimepath^=~/.vim/bundle/easygrep
let g:EasyGrepMode = 2 " 0:All, 1:Open Buffers, 2:TrackExt, 
let g:EasyGrepCommand = 1 " 0:Use vimgrep, 1:grep
let g:EasyGrepRecursive = 1 " Recursive searching 
let g:EasyGrepFilesToExclude = "*.bak, *~, *.a, *.o, *.pyc, *.bak *.so"
let g:EasyGrepWindow = 0 " 0:quickfix, 1:localtion list
let g:EasyGrepJumpToMatch = 0 " jump to first match file, default is 1

""""""
" interestingwords
set runtimepath^=~/.vim/bundle/interestingwords
nnoremap <silent> <leader>k :call InterestingWords('n')<cr>
nnoremap <silent> <leader>K :call UncolorAllWords()<cr>

